<?php
namespace Profile\Controller;
use Profile\Controller\BaseController;
class AdminsController extends BaseController {
	private $tbl;
	public function _initialize(){
		$this->tbl='users';
		$this->model=D($this->tbl);
		parent::_initialize();
	}
	public function mod(){//修改界面
		$this->display();
	}
	public function update(){//修改
		$data=I("post.");
		$position="Users/index";
		if(md5($data['ypassword'])!=$_SESSION['user']['password']){//如果密码验证不正确
			$this->error("更新失败！",U($position));
		}	
		if($data['password']==null){
			$data['password']=$_SESSION['user']['password'];
		}
			//var_dump($data);exit;
		$newdata=array(
			"name"=>$data['user'],
			"password"=>MD5($data['password']),
			"id"=>$_SESSION['user']['id']
		);
		$user=$this->model->create($newdata);
			$position="mod";
			if($user){
				$this->model->save();
				$_SESSION['user']=$newdata;
				$this->success('更新成功！',U($position));
			}else{
				$this->error("更新失败！",U($position));
			}
	}	
}